package me.jiatao.wan.di

import android.content.Context
import coil.ImageLoader
import dagger.hilt.EntryPoint
import dagger.hilt.InstallIn
import dagger.hilt.android.EntryPointAccessors
import dagger.hilt.components.SingletonComponent

/**
 * @Author: taojia
 * @CreateDate: 2021/8/27 10:28 上午
 * @Version: 1.0
 * @Description: 使用EntryPoint，对默认无法完成注入操作的类进行依赖注入
 */
@EntryPoint
@InstallIn(SingletonComponent::class)
interface GlobalEntryPoint {

    fun injectImageLoader(): ImageLoader

    companion object {
        fun resolveApplication(context: Context): GlobalEntryPoint {
            val appContext = context.applicationContext ?: throw IllegalStateException()

            return EntryPointAccessors.fromApplication(
                appContext,
                GlobalEntryPoint::class.java
            )
        }
    }
}